package com.gimi.cloud.jimi.dao.dao.sys;

import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParam;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParamProvider;
import com.gimi.cloud.jimi.dto.sys.SysMasterDTO;
import com.gimi.cloud.jimi.entity.sys.SysMasterEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shazhiwei on 2017/12/14.
 */
@Mapper
public interface SysMasterDao extends MyMapper<SysMasterEntity>,BaseDao<SysMasterEntity,SysMasterDTO> {

    @Select("SELECT * FROM sys_master WHERE username = #{userName};")
    SysMasterDTO findByUserName(@Param(value = "userName") String userName);

    @Select("SELECT * FROM sys_master WHERE is_delete = 0 AND ma_id = #{maId};")
    SysMasterDTO findById(@Param(value = "maId") Integer maId);

    @SelectProvider(method = "selectListBySql",type = QueryParamProvider.class)
    List<SysMasterDTO> queryPage(QueryParam param);

    @Update("UPDATE sys_master SET is_delete = 1 WHERE ma_id = #{maId};")
    Integer deleteMaster(@Param(value = "maId") Integer maId);

    /**
     * 查询操作员和角色id
     * @param masterId
     * @return
     */
    @Select("SELECT r.ro_id as roleId,t.* FROM sys_master t LEFT JOIN sys_master_role r ON t.ma_id = r.ma_id WHERE t.ma_id = #{masterId};")
    List<SysMasterDTO> getMasterById(@Param(value = "masterId") Integer masterId);

    @SelectProvider(method = "selectCountBySql",type = QueryParamProvider.class)
    Long getCount(QueryParam param);

}
